package com.bdqn.qnnews.swagger.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * swagger的文档信息配置
 * @author xlzhang
 */
@Configuration
@ConditionalOnClass(OpenAPI.class)
@EnableConfigurationProperties(QnSwaggerProperties.class)
public class QnOpenApiAutoConfiguration {

  @Bean
  public OpenAPI qnOpenApi(QnSwaggerProperties prop) {
    return new OpenAPI()
      // 注意这里Info要导入models包下的
      .info(new Info()
              .title(prop.getTitle())
              .description(prop.getDescription())
              .version(prop.getVersion())
               // 设置许可证名称和地址
              .license(new License().name("Apache 2.0").url("http://www.qnnews.com")))
      // 设置外部文档的描述和地址
      .externalDocs(new ExternalDocumentation()
                    .description("Stock Wiki Documentation")
                    .url("https://qnnews.com/docs"));
  }
}